<template>
  <div class="newAlbum">
    <div class="title" v-if="newAlbumWeekList && newAlbumWeekList.length">
      {{ "本周新碟" }}
    </div>
    <div class="weekAlbum" v-if="newAlbumWeekList && newAlbumWeekList.length">
      <div v-for="item in newAlbumMonthList" :key="item.id" class="albumItem">
        <img
          :src="item.picUrl"
          alt
          srcset
          width="140"
          height="140"
          @click="goAlbumInfo(item.id)"
        />
        <div @click="goAlbumInfo(item.id)">{{ item.name }}</div>
        <div>{{ item.artist }}</div>
      </div>
    </div>
    <div class="title">{{ `${new Date().getMonth() + 1}-${new Date().getDate()}` }}</div>
    <div class="monthAlbum">
      <div v-for="item in newAlbumMonthList" :key="item.id" class="albumItem">
        <img
          :src="item.picUrl"
          alt
          srcset
          width="140"
          height="140"
          @click="goAlbumInfo(item.id)"
        />
        <div @click="goAlbumInfo(item.id)">{{ item.name }}</div>
        <div @click="goAlbumInfo(item.id)">{{ item.artist }}</div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted, defineProps, ref, watch } from "vue";
import axios from "@/http";
import { useRouter } from "vue-router";
const props = defineProps({
  area: {
    type: String,
    default: "ALL",
  },
  currentChoose: {
    type: String,
    default: "全部",
  },
});
onMounted(() => {
  getNewAlbumList();
});
watch(
  () => [props.area, props.currentChoose],
  () => {
    getNewAlbumList();
  }
);
const router = useRouter();
const newAlbumWeekList = ref([]);
const newAlbumMonthList = ref([]);
const offset = ref(2);
const more = ref(true);
const goAlbumInfo = (id) => {
  router.push("/home/albumInfo/" + id);
};
const getNewAlbumList = () => {
  const typemenu = {
    全部: "new",
    推荐: "hot",
  };
  console.log(props.currentChoose);

  axios
    .get("/top/album", {
      params: {
        area: props.area,
        offset: offset.value,
        limit: 30,
        type: typemenu[props.currentChoose],
      },
    })
    .then((res) => {
      console.log(res);
      const total = res.data.total;
      newAlbumWeekList.value = res.data.weekData?.map((item) => ({
        ...item,
        artist: item.artist.name,
      }));
      newAlbumMonthList.value = res.data.monthData.map((item) => ({
        ...item,
        artist: item.artist.name,
      }));
      //   more.value = total > newAlbumList.value.length
      //   offset.value++
    });
};
</script>

<style lang="scss" scoped>
.newAlbum {
  padding: 0px 35px 60px;
  .title {
    font-size: 18px;
    font-weight: bolder;
    color: #b2b2b2;
  }
  .weekAlbum,
  .monthAlbum {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    .albumItem {
      flex-basis: 156px;
      margin-top: 16px;
      div {
        line-height: 20px;
        &:hover {
          cursor: pointer;
        }
        &:nth-child(2) {
          color: #b2b2b2;
          font-size: 14px;
          font-weight: bold;
          &:hover {
            color: #fff;
          }
        }
        &:nth-child(3) {
          color: #666;
          font-size: 12px;
          font-weight: bold;
          &:hover {
            color: #b2b2b2;
          }
        }
      }
      img {
        border-radius: 5px;
        width: 100%;
        height: 156px;
        cursor: pointer;
      }
    }
  }
}
</style>
